<form name="dbCheck" action="<?=$_SERVER[PHP_SELF]?>" method="post">
Check for 
<select name="queryObj">
<option value="alb">albums</option>
<option>files</option>
<option>tracks</option>
<option>users</option>
<option>programs</option>
</select>

with <br /> <select name="albType"><option value="no_add_date">no add date</option><option <?php 
if ($_REQUEST[albType] === 'no_tracks') echo (' selected="selected" ');
?> value="no_tracks">no tracks</option><option value="no_good_tracks"  <?php 
if ($_REQUEST[albType] === 'no_good_tracks') echo (' selected="selected" ');
?> >no good tracks</option><option value="no_cat"  <?php 
if ($_REQUEST[albType] === 'no_cat') echo (' selected="selected" ');
?> >no category</option></select>{duplicate entries}
 and is <select name="albType2"><option value="">any status</option><option value="3">in rotation</option></select>
<br />
tracks {no valid files, no album, duplicate entries}
<br />
files {no tracks, duplicate entries, }
<br />
users {with the name [__], }
<br />
programs {with overlapping times, }
<input type="hidden" name="mode" value="dbCheck" />

<input type="hidden" name="submitQuery" value="true" />
<input type="hidden" name="loading" value="true" />
<input type="submit" value="Query Database" />
</form>

<?php

if ($_REQUEST[submitQuery]) {
   ?><table>
   <?php 
   $queryObj = $_REQUEST[queryObj];
   if ($queryObj === 'alb') {
      $albType = $_REQUEST[albType];
      if ($albType === 'no_add_date') {
         $dbCheckSql = " SELECT * FROM `album` WHERE ( (`add_date` IS NULL) OR (`add_date`='') OR (`add_date`='0000-00-00') ) ";
      } else if ( $albType === 'no_cat') {
         $dbCheckSql = " SELECT * FROM `album` WHERE (`category` IS NULL) ";
      } else if ( ($albType === 'no_tracks') || ($albType === 'no_good_tracks') ) {
         $dbCheckSql = " SELECT * FROM `album` WHERE (`cddbid` IS NOT NULL) ";
      }
      if ($_REQUEST[albType2]) {
         $dbCheckSql .= " AND `status`='".$_REQUEST[albType2]."' ";
      }
      $dbCheckSql .= " ORDER BY TRIM(LEADING 'the ' FROM LOWER(`artist`)) ASC ";
      $dbCheckQuery = mysql_query($dbCheckSql);
      
      if ( ($albType == 'no_tracks') || ($albType == 'no_good_tracks') ) {
         $j=0;
         while ($albTmp = mysql_fetch_array($dbCheckQuery)) {
            if ($albType === 'no_tracks') {
               $chkTrkSql = " SELECT `id` FROM `track` WHERE (`cddbid`='".$albTmp[cddbid]."') ";
            } else if ($albType === 'no_good_tracks') {
//               echo('<h1>hi</h1>');
               $chkTrkSql = " SELECT `id` FROM `track` WHERE (`cddbid`='".$albTmp[cddbid]."') AND (`virtue`>'3') ";
            }
            $chkTrkQuery = mysql_query($chkTrkSql); 
            $albTrks = mysql_num_rows($chkTrkQuery);
            
            if (!$albTrks) {
               $alb[$j] = $albTmp;
               $j++;
            }
            unset($albTrks);
         }
      } else {
         $j=0; // iterator for forming album array
         while ($albTmp = mysql_fetch_array($dbCheckQuery)) {
            $alb[$j] = $albTmp;
            $j++;
         }
      }
      
//      var_dump($alb);
      
      if (!$alb || count($alb) == 0 ) echo ('There were zero results for your query.<br />');
      for ($i = 0; $i < count($alb); $i++) {
         printf('<tr id="queryItem[%s]"><td class="queryItem"><a href="?mode=albEdit&amp;albId=%s" title="Edit this CD"><img style="border: 0px;" height="16" width="16" title="Edit this CD" alt="edit this CD" src="./themes/%s/img/edit.png" /></a><a onClick="delAlbum(%s); document.getElementById(\'queryItem[%s]\').className = \'hidden\';"><img style="border: 0px;" height="16" width="16" title="delete this album" alt="trash, delete" src="./themes/%s/img/trash.png" /></a><a href="?mode=albEdit&albId=%s">%s</a> by %s</td></tr>', 
         $i, $alb[$i][cddbid], $theme, $alb[$i][cddbid], $i, $theme, $alb[$i][cddbid], $alb[$i][title], $alb[$i][artist]);
      }
   } else if ($queryObj === 'trk') {
      // we're looking at track db checking functions
   }
   ?>
   </table><?php 
}


//
//
// {{{}}}
//
// begin query to find two track entries linked to the same file
$testQuery = mysql_query(" SELECT COUNT(*), `filepath`,`filename` FROM `track` GROUP BY `filepath`,`filename` HAVING COUNT(*)>1 ");
while($test = mysql_fetch_array($testQuery)) {
   echo('artist doubles=');
   var_dump($test);
   echo('<br />');
}
//
// end query to find two track entries linked to the same file 
//
//


?>
